package com.dries.portal.module.portal.controller;

import com.dries.common.api.CommonResult;
import com.dries.portal.module.portal.entity.Discuss;
import com.dries.portal.module.portal.form.AddDiscussDetailForm;
import com.dries.portal.module.portal.service.IDiscussService;
import com.dries.portal.module.portal.vo.DiscussVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 用户评论表
 *
 * @author dries
 * @email samphsanie@gmail.com
 * @date 2020-08-06 15:56:47
 */
@Slf4j
@Api(tags = "评价推荐API", value = "DiscussController")
@RestController
@RequestMapping("/portal/discuss")
public class DiscussController {

    @Resource
    private IDiscussService discussService;

    /**
     * 列表
     */
    @ApiOperation("用户评价推荐列表")
    @GetMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "10", required = false) Integer pageSize,
                             @RequestParam(defaultValue = "1", required = false) Integer pageNum){
        PageInfo<DiscussVo> discussVos = discussService.listByDiscussVo(pageNum, pageSize);
        return CommonResult.success(discussVos);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public CommonResult info(@PathVariable("id") Integer id){
		Discuss discuss = discussService.getById(id);

        return CommonResult.success(discuss);
    }

    /**
     * 保存
     */
    @ApiOperation("用户评价")
    @PostMapping("/save")
    public CommonResult save(@RequestBody AddDiscussDetailForm discuss){

		// discussService.save(discuss);
		return discussService.saveByAddDiscussDetailForm(discuss);

    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public CommonResult update(@RequestBody Discuss discuss){
		discussService.updateById(discuss);

        return CommonResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public CommonResult delete(@RequestBody Integer[] ids){
		discussService.removeByIds(Arrays.asList(ids));

        return CommonResult.success();
    }

}
